﻿using System;
using System.Reflection.Metadata.Ecma335;
public class Math
{
    public double Add(double a,double b)
    { return a + b; }
    public double Subtract(double a, double b)
    { return a - b; }
    public double Multiply(double a,double b)
    { return a * b; }
    public double Divide(double a, double b)
    { return a / b; }

}
class Program
{
    static void Main(string[] args)
    {
        Math math  = new Math();
        Console.WriteLine("用户输入测试");
        Console.Write("请输入第一个数字：");
        double input1=Convert.ToDouble(Console.ReadLine());
        Console.Write("请输入第二个数字：");
        double input2 = Convert.ToDouble(Console.ReadLine());
        Console.Write("请选择运算（+，-，*，/）：");
        string operation=Console.ReadLine();
        double result = 0;
        switch(operation)
        {
            case "+":
                result = math.Add(input1, input2);
                break;
            case "-":
                result = math.Subtract(input1, input2);
                break;
            case "*":
                result = math.Multiply(input1, input2);
                break;
            case "/":
                try
                {
                    result = math.Divide(input1, input2);
                }
                catch (DivideByZeroException ex)
                {
                    Console.WriteLine($"错误: {ex.Message}");
                    return;
                }
                break;
            default:
                Console.WriteLine("无效的运算符");
                return;
        }
        Console.WriteLine($"{input1} {operation} {input2} = {result}");

        Console.WriteLine("\n测试完成，按任意键退出...");
        Console.ReadKey();
    }
}

